﻿String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

$(document).ready(function() {
    bindcblList();
});

function Addcheckform() {
    var pssx = $("#ctl00_MainContent_dropPSSX option:selected").val();
    if (pssx == "#") {
        alert("请选择评审事项！");
        return false;
    }
    if ($("#ctl00_MainContent_lblJBYQ").length > 0) {
        alert("请设置考评标准代码！");
        return false;
    }
    var i = 0;
    var j = 0;
    $("input[id^='ctl00_MainContent_rblJBYQ_']").each(function() {
        i++;
        if ($(this).attr("disabled") == true) {
            j++;
        }
    });
    if (Number(i) == Number(j)) {
        alert("该评审事项都已考评！");
        return false;
    }
    var yanzheng = false;
    $("input[id^='ctl00_MainContent_rblJBYQ_']").each(function() {
        if ($(this).attr("checked") == true) {
            yanzheng = true;
        }
    });
    if (yanzheng == false) {
        alert("请选择考评基本要求！");
        return false;
    }
    yanzheng = false;
    $("input[id^='ctl00_MainContent_cblKPBZ_']").each(function() {
        if ($(this).attr("checked") == true) {
            yanzheng = true;
        }
    });
    if (yanzheng == false) {
        alert("请选择扣分标准！");
        return false;
    }
    if ($("#ctl00_MainContent_txtKFQKSM").val().toString() == "") {
        alert("请填写扣分说明！");
        return false;
    }
    if ($("#ctl00_MainContent_txtKPKF").val().toString() != "") {
        var mode = /^[0-9]{1,2}\.?[0-9]{0,2}$/;
        if (!mode.test($("#ctl00_MainContent_txtKPKF").val().toString())) {
            alert("合计扣分必须是数字类型！");
            return false;
        }
    }
    else {
        alert("请填写合计扣分！");
        return false;
    }
    var hjkf = $("#ctl00_MainContent_txtKPKF").val().toString();
    var kf = 0;
    $("input[id^='ctl00_MainContent_cblKPBZ_']").each(function() {
        if ($(this).attr("checked") != "") {
            var r = $(this).parent().attr("KF");
            var r1, r2, m;
            try { r1 = kf.toString().split(".")[1].length } catch (e) { r1 = 0 };
            try { r2 = r.toString().split(".")[1].length } catch (e) { r2 = 0 };
            m = Math.pow(10, Math.max(r1, r2));
            kf = (kf * m + r * m) / m;
        }
    });
    if (Number(kf) < Number(hjkf)) {
        alert("合计扣分超过上限");
        return false;
    }
}
function Updatecheckform() {
    var yanzheng = false;
    $("input[id^='ctl00_MainContent_cblKPBZ_']").each(function() {
        if ($(this).attr("checked") == true) {
            yanzheng = true;
        }
    });
    if (yanzheng == false) {
        alert("请选择扣分标准！");
        return false;
    }
    if ($("#ctl00_MainContent_txtKFQKSM").val().toString() == "") {
        alert("请填写扣分说明！");
        return false;
    }
    if ($("#ctl00_MainContent_txtKPKF").val().toString() != "") {
        var mode = /^[0-9]{1,2}\.?[0-9]{0,2}$/;
        if (!mode.test($("#ctl00_MainContent_txtKPKF").val().toString())) {
            alert("合计扣分只能输入数字！");
            return false;
        }
    }
    else {
        alert("请填写合计扣分！");
        return false;
    }
    var hjkf = $("#ctl00_MainContent_txtKPKF").val().toString();
    var kf = 0;
    $("input[id^='ctl00_MainContent_cblKPBZ_']").each(function() {
        if ($(this).attr("checked") != "") {
            var r = $(this).parent().attr("KF");
            var r1, r2, m;
            try { r1 = kf.toString().split(".")[1].length } catch (e) { r1 = 0 };
            try { r2 = r.toString().split(".")[1].length } catch (e) { r2 = 0 };
            m = Math.pow(10, Math.max(r1, r2));
            kf = (kf * m + r * m) / m;
        }
    });
    if (Number(kf) < Number(hjkf)) {
        alert("合计扣分超过上限");
        return false;
    }
}

function bindcblList() {
    var kf = 0;
    if ($("#ctl00_MainContent_txtKPKF").value != "") {
        kf = $("#ctl00_MainContent_txtKPKF").val().toString();
    }
    $("input[id^='ctl00_MainContent_cblKPBZ_']").each(function() {
        $(this).bind("click", function() {
            if ($(this).attr("checked") != "") {
                $("#ctl00_MainContent_txtKFQKSM").val($("#ctl00_MainContent_txtKFQKSM").val() + $(this).next().text() + "\r");
            }
            else {
                var txt = $("#ctl00_MainContent_txtKFQKSM").val().replace($(this).next().text(), "");
                $("#ctl00_MainContent_txtKFQKSM").val(txt);
            }
            if ($(this).attr("checked") != "") {
                var r = $(this).parent().attr("KF");
                var r1, r2, m;
                try { r1 = kf.toString().split(".")[1].length } catch (e) { r1 = 0 };
                try { r2 = r.toString().split(".")[1].length } catch (e) { r2 = 0 };
                m = Math.pow(10, Math.max(r1, r2));
                kf = (kf * m + r * m) / m;
            }
            else {
                var r = $(this).parent().attr("KF");
                var r1, r2, m;
                try { r1 = kf.toString().split(".")[1].length } catch (e) { r1 = 0 };
                try { r2 = r.toString().split(".")[1].length } catch (e) { r2 = 0 };
                m = Math.pow(10, Math.max(r1, r2));
                kf = (kf * m - r * m) / m;
            }
            $("#ctl00_MainContent_txtKPKF").val(kf);
        });

    });
}